package ee.example.final_work

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.example.final_work.R

class MyAdapter2(private val mData: List<NewsBean>, private val mContext: Context) : BaseAdapter() {
    override fun getCount(): Int {
        return mData.size
    }

    override fun getItem(position: Int): NewsBean {
        return mData[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View, parent: ViewGroup): View {
        var convertView = convertView
        val viewHolder: ViewHolder
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false)
            viewHolder = ViewHolder()
            viewHolder.txt_item_title =
                convertView.findViewById<View>(R.id.txt_item_title) as TextView
            convertView.tag = viewHolder
        } else {
            viewHolder = convertView.tag as ViewHolder
        }
        viewHolder.txt_item_title!!.text = mData[position].title
        return convertView
    }

    private inner class ViewHolder {
        var txt_item_title: TextView? = null
    }
}